package com.koron.css2.systemManage.servlet;

import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.systemManage.bean.OrgUserBean;
import com.koron.css2.systemManage.bean.query.OrgUserQueryBean;
import com.koron.css2.systemManage.service.IRoleService;
import com.koron.css2.systemManage.service.ServiceFactory;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 获取角色用户列表
 * @author 59532
 *
 */
public class RoleUserList implements ServerInterface {
	
	private static Logger log = LogManager.getLogger(RoleUserList.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<PageInfo> msg = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
		try {
			OrgUserQueryBean query = JsonUtils.objectToPojo(req.getData(), OrgUserQueryBean.class);
			if(StringUtils.isEmpty(query.getRoleCode())) {
				msg.setCode(Constant.MESSAGE_INT_FAIL);
				msg.setDescription("角色不能为空");
				return msg;
			}
			IRoleService roleService = ServiceFactory.getRoleService();
			PageInfo<OrgUserBean> page = roleService.listUserByRole(factory, query.getRoleCode(), query.getPage(), query.getPageCount());
			msg.setData(page);
		} catch (Exception e) {
			log.error("查询用户出错：" + e);
			msg.setCode(Constant.MESSAGE_INT_FAIL);
			msg.setDescription("查询用户出错");
		}
		return msg;
	}

}
